//
//  MainTabBarController.m
//  iOS-CtrlV
//
//  Created by Wang Li on 12-12-19.
//  Copyright (c) 2012年 Wang Li. All rights reserved.
//

#import "MainTabBarController.h"
#import "HomePageViewController.h"
#import "GreyOrViewController.h"
#import "ExaminationRemindViewController.h"
#import "ConsultingViewController.h"
#import "PersonalSettingViewController.h"


@interface MainTabBarController ()

@end

@implementation MainTabBarController
@synthesize m_UserDic;
@synthesize mainTabbarCustom = m_TabbarCustom;
@synthesize mainselectedIndex;
- (id)init
{
    if (self = [super init]) {
        // Custom initialization
//        m_TabbarCustom = [[UIView alloc] initWithFrame:CGRectMake(0, 480-20-44-49, 320, 49)];
//        [m_TabbarCustom setBackgroundColor:[UIColor colorWithRed:236/255.f green:238/255.f blue:235/255.f alpha:1]];
//        m_TabbarCustom.clipsToBounds =NO;
//        self.tabBar.opaque =NO;
//        self.tabBar.clipsToBounds =NO;
//        _IsFirstIn =YES;
//        
//        
//        UIButton* tBarBtt0 = [UIButton buttonWithType:UIButtonTypeCustom];
//        [tBarBtt0 setTitle:@"首页" forState:UIControlStateNormal];
//        [tBarBtt0 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        tBarBtt0.frame =CGRectMake(0, 0, 64, 49);
//        tBarBtt0.tag =10;
//        
//        UIButton* tBarBtt1 = [UIButton buttonWithType:UIButtonTypeCustom];
//        [tBarBtt1 setTitle:@"报名查分" forState:UIControlStateNormal];
//        [tBarBtt1 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//        tBarBtt1.frame =CGRectMake(64, 0, 64, 49);
//        tBarBtt1.tag=11;
//        
//        UIButton* tBarBtt2 = [UIButton buttonWithType:UIButtonTypeCustom];
//        [tBarBtt2 setTitle:@"考试提示" forState:UIControlStateNormal];
//        [tBarBtt2 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//        tBarBtt2.frame =CGRectMake(128, 0, 64, 49);
//        tBarBtt2.tag =12;
//        
//        UIButton* tBarBtt3 = [UIButton buttonWithType:UIButtonTypeCustom];
//        [tBarBtt3 setTitle:@"在线咨询" forState:UIControlStateNormal];
//        [tBarBtt3 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//        tBarBtt3.frame =CGRectMake(192, 0, 64, 49);
//        tBarBtt3.tag =13;
//        
//        UIButton* tBarBtt4 = [UIButton buttonWithType:UIButtonTypeCustom];
//        tBarBtt4.frame =CGRectMake(256, 0, 64, 49);
//        [tBarBtt3 setTitle:@"个人" forState:UIControlStateNormal];
//        [tBarBtt3 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//        tBarBtt4.tag =14;
//        
//        
//        [tBarBtt0 addTarget:self action:@selector(customBttPressed:) forControlEvents:UIControlEventTouchUpInside];
//        [tBarBtt1 addTarget:self action:@selector(customBttPressed:) forControlEvents:UIControlEventTouchUpInside];
//        [tBarBtt2 addTarget:self action:@selector(customBttPressed:) forControlEvents:UIControlEventTouchUpInside];
//        [tBarBtt3 addTarget:self action:@selector(customBttPressed:) forControlEvents:UIControlEventTouchUpInside];
//        [tBarBtt4 addTarget:self action:@selector(customBttPressed:) forControlEvents:UIControlEventTouchUpInside];
//        
//        
//        [m_TabbarCustom addSubview:tBarBtt0];
//        [m_TabbarCustom addSubview:tBarBtt1];
//        [m_TabbarCustom addSubview:tBarBtt2];
//        [m_TabbarCustom addSubview:tBarBtt3];
//        [m_TabbarCustom addSubview:tBarBtt4];
        
        _WillSeeTag =-1;
    }
    return self;
}

-(void) dealloc
{
    [m_UserDic release];
    [m_TabbarCustom release];

    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

	// Do any additional setup after loading the view.

    HomePageViewController* tHomePage = [[HomePageViewController alloc] init];
    GreyOrViewController* tGreyOr = [[GreyOrViewController alloc] init];
    ExaminationRemindViewController* tExaminationRemind = [[ExaminationRemindViewController alloc] init];
    ConsultingViewController* tConsulting = [[ConsultingViewController alloc] init];
    PersonalSettingViewController* tPersonalSetting = [[PersonalSettingViewController alloc] init];
//    tHomePage.hidesBottomBarWhenPushed =YES;
//    tGreyOr.hidesBottomBarWhenPushed =YES;
//    tExaminationRemind.hidesBottomBarWhenPushed =YES;
//    tConsulting.hidesBottomBarWhenPushed =YES;
//    tPersonalSetting.hidesBottomBarWhenPushed =YES;
    UINavigationController* tNav0 = [[UINavigationController alloc] initWithRootViewController:tHomePage];
    tNav0.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"tabBar_item1.png"] tag:0]autorelease];
    UINavigationController* tNav1 = [[UINavigationController alloc] initWithRootViewController:tGreyOr];
    tNav1.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"报名查分" image:[UIImage imageNamed:@"tabBar_item2.png"] tag:1] autorelease];
    UINavigationController* tNav2 = [[UINavigationController alloc] initWithRootViewController:tExaminationRemind];
    tNav2.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"考试提醒" image:[UIImage imageNamed:@"tabBar_item4.png"] tag:2] autorelease];
    UINavigationController* tNav3 = [[UINavigationController alloc] initWithRootViewController:tConsulting];
    tNav3.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"在线咨询" image:[UIImage imageNamed:@"tabBar_item3.png"] tag:3] autorelease];
    UINavigationController* tNav4 = [[UINavigationController alloc] initWithRootViewController:tPersonalSetting];
    tNav4.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"个人" image:[UIImage imageNamed:@"tabBar_item5.png"] tag:4] autorelease];
    
    [tHomePage release];
    [tGreyOr release];
    [tExaminationRemind release];
    [tConsulting release];
    [tPersonalSetting release];
    
    self.viewControllers =[NSArray arrayWithObjects:tNav0,tNav1,tNav2,tNav3, tNav4,nil];
    
    [tNav0 release];
    [tNav1 release];
    [tNav2 release];
    [tNav3 release];
    [tNav4 release];
    self.selectedIndex = 0;

}

//-(void) viewWillAppear:(BOOL)animated
//{
//    for (id subObject in self.tabBar.subviews) {
//        //NSLog(@"%@",[subObject description]);
//        if ([NSStringFromClass([subObject class]) isEqualToString:@"UITabBarButton"]) {
//            [subObject removeFromSuperview];
//        }
//    }
//}



//-(void) loginOkToShowTag
//{
//    if (_WillSeeTag > 0) {
//        UIButton* tBarBtt =(UIButton*)[m_TabbarCustom viewWithTag:_WillSeeTag];
//        [self customBttPressed:tBarBtt];
//        _WillSeeTag =-1;
//    }
//    
//}


//-(void) registLogin
//{
//    UIButton* tBarBtt =(UIButton*)[m_TabbarCustom viewWithTag:11];
//    self.m_UserDic = nil;
//    self.mainTabbarCustom.hidden=NO;
//    UINavigationController* tNav = [self.viewControllers objectAtIndex:0];
//
//    
//    UINavigationController* tNavc = [self.viewControllers objectAtIndex:1];
//    [tNavc popToRootViewControllerAnimated:NO];
//    [self customBttPressed:tBarBtt];
//}
//
//-(void) customBttPressed:(UIButton*)f_sender
//{
//    int tType =f_sender.tag-10;
//    switch (tType) {
//        case 0:
//        {
//
//            self.selectedIndex = 0;
//        }
//            break;
//        case 1:
//            self.selectedIndex = 1;
//            break;
//        case 2:
//            self.selectedIndex = 2;
//            break;
//        case 3:
//        {
//
//            self.selectedIndex = 3;
//        }
//            break;
//        case 4:
//        {
//
//        }
//            break;
//    }
//    [self flashBttColor];  
//}
//
//-(void) flashBttColor
//{
//    UIButton* tBarBtt0 =(UIButton*)[m_TabbarCustom viewWithTag:10];
//    UIButton* tBarBtt1 =(UIButton*)[m_TabbarCustom viewWithTag:11];
//    UIButton* tBarBtt2 =(UIButton*)[m_TabbarCustom viewWithTag:12];
//    UIButton* tBarBtt3 =(UIButton*)[m_TabbarCustom viewWithTag:13];
//    
//    [tBarBtt0 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//    [tBarBtt1 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//    [tBarBtt2 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//    [tBarBtt3 setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//    
//    UIButton* tBlackBtt = (UIButton*)[m_TabbarCustom viewWithTag:10+self.selectedIndex];
//    [tBlackBtt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//}

+ (UILabel*)setTitle:(NSString*)titletext
{
//    CGSize iSize = [titletext sizeWithFont:[UIFont boldSystemFontOfSize:22.0f]];
    UILabel* title = [[[UILabel alloc] initWithFrame:CGRectMake(0, 12, 320, 22)] autorelease];
    [title setText:titletext];
    title.textAlignment =UITextAlignmentCenter;
    title.font = [UIFont boldSystemFontOfSize:22.0f];
    title.textColor = [UIColor whiteColor];
    title.backgroundColor = [UIColor clearColor];
    title.tag = 144;
    return title;
}


@end
